package api

import (
	"github.com/kataras/iris/context"
	"server/bitkop/core"
	"global/constants"
	"github.com/garyburd/redigo/redis"
	"github.com/ngaut/log"
	"encoding/json"
	"server/bitkop/app/common"
	constants2 "server/bitkop/app/constants"
)

func InfoMarket(ctx context.Context) {

	conn := core.BK.Redis.OTEPool.Get()
	defer conn.Close()

	var infos map[string][]map[string]string
	data, err := redis.String(conn.Do("GET", constants.OrderInfoFresh))
	if err != nil {
		log.Errorf("get info fresh error, msg: %s", err.Error())
		ctx.JSON(common.Success(infos))
		return
	}

	err = json.Unmarshal([]byte(data), &infos)
	if err != nil {
		log.Errorf("json unmarshal info fresh error, msg: %s", err.Error())
		ctx.JSON(common.Error(constants2.INNER_ERROR))
		return
	}

	ctx.JSON(common.Success(infos))
}